package cn.hsw.component.web.validated.valid;

import cn.hsw.component.core.util.Validator;
import cn.hsw.component.web.validated.annotations.UserName;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 用户验证
 * @author 李子木
 * @date 2020-11-06
 */
public class UserNameValid implements ConstraintValidator<UserName,String> {
    @Override
    public void initialize(UserName constraintAnnotation) {

    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {

        if(!Validator.isEmpty(s)) {
            return Validator.isUserName(s);
        }else{
            return false;
        }
    }
}
